//
//  PublicWebViewCtrl.m
//  Traveling
//
//  Created by Northwan on 15/6/10.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "PublicWebViewCtrl.h"

@interface PublicWebViewCtrl ()<UIWebViewDelegate>
@property (strong, nonatomic) UIWebView *webView;
@property (copy, nonatomic) NSString *url;

@end

@implementation PublicWebViewCtrl

-(instancetype)initWithUrl:(NSString *)url{
    self = [super init];
    if(self){
        self =  [[PublicWebViewCtrl alloc]init];
        self.url = url;
    }
    return self;
}

- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    CGSize actualSize = [_webView sizeThatFits:CGSizeZero];
    _webView.scrollView.contentSize = actualSize;
    
    NSString *theTitle=[webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    self.title = theTitle;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height-64)];
    self.webView.scalesPageToFit = YES;//自动对页面进行缩放以适应屏幕
    [self.webView setDelegate:self];
    [self.view addSubview:self.webView];
    
    NSURL* url = [NSURL URLWithString:self.url];
    NSURLRequest* request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
}

@end
